﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using log4net.Appender;
using log4net;
using System.Reflection;
namespace UTIL
{
    public enum ErrorType : int
    {
        Error,
        Fatal,
        Info,
        Debug,
        Warn
    };
    public class CException
    {
       
        public void SaveExcetpion(Exception e)
        {
            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            log.Fatal("fatal", e);
            //记录错误日志
        }


        public static void SaveExcepiton(ErrorType et,Exception e)
        {
            ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            if (et == ErrorType.Error)
            {
                log.Fatal("error", e);
            }
            else if (et == ErrorType.Fatal)
            {
                log.Fatal("fatal", e);
            }
            else if (et == ErrorType.Info)
            {
                log.Fatal("info", e);
            }
            else if (et == ErrorType.Debug)
            {
                log.Fatal("debug", e);
            }
            else if (et == ErrorType.Warn)
            {
                log.Fatal("warn", e);
            }
        }

        public static  void SaveExcepiton(ErrorType et, Exception e, Type ty)
        {
            ILog log = log4net.LogManager.GetLogger(ty);
            if (et == ErrorType.Error)
            {
                log.Fatal("error", e);
            }
            else if (et == ErrorType.Fatal)
            {
                log.Fatal("fatal", e);
            }
            else if (et == ErrorType.Info)
            {
                log.Fatal("info", e);
            }
            else if (et == ErrorType.Debug)
            {
                log.Fatal("debug", e);
            }
            else if (et == ErrorType.Warn)
            {
                log.Fatal("warn", e);
            }
        }

        public static void SetLog(String strConent)
        {
            ILog log = log4net.LogManager.GetLogger(strConent);
            log.Info(strConent);
        }
    }
}
